/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package control;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author TranDangThuan
 */
public class AccountsController {
    public static boolean login(String user, String pass){
        Connection conn = DBUtility.openConnection();
        if (conn != null) {
            try {
                PreparedStatement ps = conn.prepareStatement("Select AccSerialNo from Accounts where AccSerialNo=? and AccPassword=?");
                ps.setString(1, user);
                ps.setString(2, pass);
                ResultSet rs = ps.executeQuery();
                return rs.next();
            } catch (Exception ex) {
                Logger.getLogger(AccountsController.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return false;
    }
    
    public static String getPermission(String user, String pass){
        Connection conn = DBUtility.openConnection();
        try {
            PreparedStatement ps = conn.prepareStatement("Select OfficerRole from Accounts where AccSerialNo=? and AccPassword=?");
            ps.setString(1, user);
            ps.setString(2, pass);
            ResultSet rs = ps.executeQuery();
            rs.next();
            return rs.getString(1);
        } catch (SQLException ex) {
            Logger.getLogger(AccountsController.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
}
